﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IntraVision.Web;

namespace Model
{
    partial class ScheduleDay : IWorkingHours
    {
        public Schedule Schedule { get { return SchedulePeriod.Schedule; } }
        public WorkingHoursType Type { get { return WorkingHoursType.Period; } }
        public int EditId { get { return SchedulePeriodId; } }

        public string Interval {
            get { return string.Format("{0} Расписание действует с {1} по {2}", !string.IsNullOrEmpty(SchedulePeriod.Description) ? SchedulePeriod.Description + Environment.NewLine : "", SchedulePeriod.DateStart.ToDateString(), SchedulePeriod.DateEnd.HasValue ? SchedulePeriod.DateEnd.ToDateString() : "&infin;"); }
        }

        public bool IsWorkingTime(int h, int m)
        {
            if (!TimeStart.HasValue) return false;

            TimeSpan _time = new TimeSpan(h, m, 0);
            if (BreakStart.HasValue && BreakStart.Value.TimeOfDay <= _time && BreakEnd.Value.TimeOfDay > _time) return false;
            if (TimeStart.Value.TimeOfDay <= _time && TimeEnd.Value.TimeOfDay > _time) return true;

            return false;
        }
    }
}
